package com.datastructure.test.intersectionintwolist;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class IntersectionInTwoList {

    public static void main(String[] args) {

    }

    public ArrayList<Integer> intersection (ArrayList<Integer> nums1, ArrayList<Integer> nums2) {
        // write code here
        if(nums1==null||nums2==null){
            return null;
        }
        ArrayList<Integer> result = new ArrayList<>();
        List<Integer> collect = nums1.stream().distinct().collect(Collectors.toList());
        List<Integer> collect1 = nums2.stream().distinct().collect(Collectors.toList());
        for (Integer integer : collect) {
            if(collect1.contains(integer)){
                result.add(integer);
            }
        }
        return result;
    }
}
